<?php
/**
 * Created by PhpStorm.
 * User: hebidu
 * Date: 15/12/21
 * Time: 10:30
 */

namespace Admin\Controller;

use Shop\Api\RedEnvelopeApi;
use Shop\Model\RedEnvelopeModel;

class RedEnvelopeController extends AdminController {

    public function index(){
        $this->by_display();
    }

    public function add(){
        if(IS_POST){
            $uid = $this->_post('uid','','缺少UID');
            $money = $this->_post('money',0,'红包金额不能为 0');
            $notes = $this->_post('notes','');
            $dtree_type = $this->_post('dtree_type','','红包类别必须');
            $condition = $this->_post('condition',0);

            $entity = array(
                'uid'=>$uid,
                'money'=>$money,
                'notes'=>$notes,
                'dtree_type'=>$dtree_type,
                'use_condition'=>$condition,
                'use_status'=>RedEnvelopeModel::NOT_USE,
                'expire_time'=>time()+3600*24,
                'get_time'=>time(),

            );

            $result = apiCall(RedEnvelopeApi::ADD,array($entity));

            $this->checkApiCallResult($result);

            $this->success("添加成功!",U('Home/'));

        }else{
            $this->by_display();
        }
    }

}